package com.foreknow.demo03;

//已知一个数组{1,23,56,13,56,78,90,26,112}计算数组中的平均值、最大值、最小值
//注意：以上的题都用方法来实现
public class Methodtest02 {
    public static void fangfa(int []array){
        int length = array.length;
        int sum = 0;
        int max = 0;
        int min = 9999;
        for (int i = 0;i<array.length;i++){
            sum += array[i];
        }
        for (int i = 0;i<array.length;i++){
             max = array[i];
            if (max<array[i]){
                max = array[i];
            }
        }
        for (int i = 0;i<array.length;i++){
            if (min>array[i]){
                min = array[i];
            }
        }
        double average = sum/array.length;
        System.out.println("平均值是："+ average);
        System.out.println("最大值是：" + max);
        System.out.println("最小值为：" + min);
    }
    public static void main(String[] args) {
        int [] array = {1,23,56,13,56,78,90,26,112};

        Methodtest02.fangfa(array);
    }
}
